#include "myFunctions.h"
#include "RBF.h"
int main(int argc,char *argv[]){
	srand(time(NULL));
	vector<vector<double> > X;
	vector<int> Y;
	vector<double> errores;
	int numParticiones;
	double desvioDatos;
	int numPatterns;
	double porcTT;

	loadConfig(numPatterns,numParticiones,porcTT,desvioDatos);
	cout<<"Carga config"<<endl;
	cout<<"numParticiones: "<<numParticiones<<" - numPatterns: "<<numPatterns<<" - porcTT: "<<porcTT<<" - desvioDatos: "<<desvioDatos<<endl;
	//genRandom("iris.csv", "irisRandomTest.txt", desvioDatos, numPatterns);
	//cout<<"genero random"<<endl;
	readFile(X,Y,"iris.csv",false);
	cout<<"lee del archivo de datos"<<endl;
	particionado(X,Y,porcTT/100,numParticiones);
	cout<<"termina particionado"<<endl;

	for(int i=0; i<numParticiones; i++){
		cout<<"empieza particion "<<i<<endl;
		vector<vector<double> > X_training, X_test;
		vector<vector<int> > Y_training,Y_test;
		vector<int> Y_training_aux, Y_test_aux;
		stringstream cvz;
		cvz<<i;
		string snumero = cvz.str();
		string nomArchi = "Training/partTraining"+snumero+".txt";
		readFile(X_training,Y_training_aux,nomArchi,false);
		Y_training.resize(Y_training_aux.size());
		cout<<"dps de levantar"<<endl;
		for(int j=0;j<Y_training_aux.size();j++){
			Y_training[j].resize(3);
			if (Y_training_aux[j]==0){
				Y_training[j][0] = 1;
				Y_training[j][1] = -1;
				Y_training[j][2] = -1;
			}
			else{
				if (Y_training_aux[j]==1){ // ==1
					Y_training[j][0] = -1;
					Y_training[j][1] = 1;
					Y_training[j][2] = -1;
				}
				else{ // ==2
					Y_training[j][0] = -1;
					Y_training[j][1] = -1;
					Y_training[j][2] = 1;
				}
			}
			view_vi(Y_training[j]);
			cout<<"size x_tr[j] "<<X_training[j].size()<<endl;
		}
		
		RBF rbf("config_iris.txt");
		cout<<"Inicializa rbf"<<endl;
		rbf.training(X_training,Y_training);
		
		nomArchi="Test/partTest"+snumero+".txt";
		readFile(X_test,Y_test_aux,nomArchi,false);
		Y_test.resize(Y_test_aux.size());
		for(int j=0;j<Y_test_aux.size();j++){
			Y_test[j].resize(3);
			if (Y_test_aux[j]==0){
				Y_test[j][0] = 1;
				Y_test[j][1] = -1;
				Y_test[j][2] = -1;
			}
			else{
				if (Y_test_aux[j]==1){ // ==1
					Y_test[j][0] = -1;
					Y_test[j][1] = 1;
					Y_test[j][2] = -1;
				}
				else{ // ==2
					Y_test[j][0] = -1;
					Y_test[j][1] = -1;
					Y_test[j][2] = 1;
				}
			}
		}
		errores.push_back(rbf.test(X_test,Y_test));
	}
	cout<<"Promedio de Errores: "<<media(errores)<<endl;
	return 1;
}
